<?php

namespace App\Http\Controllers\Api\V1;

use App\Models\Course;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class CourseController extends BaseController
{
    /**
     *
     * 获取用户的通知消息列表
     * @param {Object} Request
     */
    public function index(Request $request)
    {
    	$type = $request->get('type', -1);
        //当前页数 默认1
    	$page = $request->get('page', 1);
    	//每页的条数
    	$perPage = 10;
    	//计算每页分页的初始位置
    	$offset = ($page * $perPage) - $perPage;
    	$courses = Course::orderBy('id', 'desc')->where('status', 1)->paginate($perPage);
    	$dataArry = $courses->toArray();
		
		foreach($dataArry['data'] as $index => $one){
			if(!$one['pic']){
				continue;
			}
			$dataArry['data'][$index]['pic'] = $this->imageBaseUrl . $one['pic'];
		}
    	
    	return $this->returnSuccess($dataArry);
    }
	
	/**
	 *
	 * 获取通知消息id的详细内容
	 * @param {Object} Request
	 */
	public function detail(Request $request)
	{
	    $id = $request->get('id');
		$detail = Course::where('id', $id)->first();
		if($detail && isset($detail['pic'])){
			$detail['pic'] = $this->imageBaseUrl . $detail['pic'];
		}
		
		return $this->returnSuccess($detail);
	}
	
	
}
